import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { InboxOutlined } from '@ant-design/icons';
import { ConfigProvider, Upload } from 'antd-v4';
import React, { useContext } from 'react';
import { createField } from '../../BaseForm/createField';
/**
 * 拖动上传组件
 *
 * @param
 */

var BaseProFormUploadDragger = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var fieldProps = _ref.fieldProps,
      _ref$title = _ref.title,
      title = _ref$title === void 0 ? '单击或拖动文件到此区域进行上传' : _ref$title,
      _ref$icon = _ref.icon,
      icon = _ref$icon === void 0 ? _jsx(InboxOutlined, {}) : _ref$icon,
      _ref$description = _ref.description,
      description = _ref$description === void 0 ? '支持单次或批量上传' : _ref$description,
      action = _ref.action,
      accept = _ref.accept,
      _onChange = _ref.onChange,
      value = _ref.value,
      children = _ref.children,
      max = _ref.max,
      proFieldProps = _ref.proFieldProps;
  var context = useContext(ConfigProvider.ConfigContext);
  var baseClassName = context.getPrefixCls('upload'); // 如果配置了 max ，并且 超过了文件列表的大小，就不展示按钮

  var showUploadButton = (max === undefined || !value || (value === null || value === void 0 ? void 0 : value.length) < max) && (proFieldProps === null || proFieldProps === void 0 ? void 0 : proFieldProps.mode) !== 'read' && (proFieldProps === null || proFieldProps === void 0 ? void 0 : proFieldProps.readonly) !== true;
  return _jsxs(Upload.Dragger // @ts-ignore
  , _objectSpread(_objectSpread({
    // @ts-ignore
    ref: ref,
    name: "files",
    action: action,
    accept: accept,
    fileList: value
  }, fieldProps), {}, {
    onChange: function onChange(info) {
      _onChange === null || _onChange === void 0 ? void 0 : _onChange(info);

      if (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.onChange) {
        fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.onChange(info);
      }
    },
    style: _objectSpread(_objectSpread({}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style), {}, {
      display: !showUploadButton ? 'none' : undefined
    }),
    children: [_jsx("p", {
      className: "".concat(baseClassName, "-drag-icon"),
      children: icon
    }), _jsx("p", {
      className: "".concat(baseClassName, "-text"),
      children: title
    }), _jsx("p", {
      className: "".concat(baseClassName, "-hint"),
      children: description
    }), children ? _jsx("div", {
      className: "".concat(baseClassName, "-extra"),
      style: {
        padding: 16
      },
      children: children
    }) : null]
  }));
});
var ProFormUploadDragger = createField(BaseProFormUploadDragger, {
  getValueFromEvent: function getValueFromEvent(value) {
    return value.fileList;
  }
});
export default ProFormUploadDragger;